/*
 * @Author: moonwater 13812995013@163.com
 * @Date: 2025-02-28 11:30:48
 * @LastEditors: moonwater 13812995013@163.com
 * @LastEditTime: 2025-02-28 14:23:53
 * @FilePath: \盐师22Git仓库\day05\Test05.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day05;

public class Test05 {
    public static void main(String[] args) {
        // System.out.println("Hello Test05!");
        int[] array = {1,2,3,4,5 };
        double avg = getAvg(array);
        System.out.println("该数组的平均值是：" +avg);
    }
    public static double getAvg(int[] arr){
        // double avg =0;
        // //遍历数组，求和
        // //元素和 除以 数组长度
        //  for(int i = 0;i < arr.length;i++){
        //     avg+=arr[i];
        //  }
        //  System.out.println(avg/arr.length);
        // return avg/arr.length;
        double avg = 0;
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
            
        }
        avg=sum/arr.length;
        return avg;
    }
}
